 package com.zxm.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zxm.pojo.UserBodyInfo;
import com.zxm.pojo.UserInfo;
import com.zxm.result.GuhealthResult;
import com.zxm.service.ContentCategoryService;
import com.zxm.service.UserBodyInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user/body")
public class UserBodyInfoController {
    @Reference
    private UserBodyInfoService userBodyInfoService;

    //根据条件查询用户身体数据（一段时间范围内）
    @RequestMapping("/getUserBodyInfoByCondition")
    @ResponseBody
    public List<UserBodyInfo> getUserBodyInfo(UserInfo userInfo,Date start,Date end) {
        return userBodyInfoService.getAll(userInfo.getUsername(),start, end);
    }

    //用户身体信息录入保存
    @RequestMapping("/addUserBodyInfo")
    @ResponseBody
    public GuhealthResult addUserBodyInfo(UserBodyInfo userBodyInfo,String username) {
        System.out.println(userBodyInfo);
        System.out.println(username);
        if(userBodyInfo!=null) {
            userBodyInfoService.insertUserBodyInfo(userBodyInfo,username);
            return GuhealthResult.success();
        }
        return GuhealthResult.fail();
    }

    //根据用户ID来展示用户最新的身体数据
    @RequestMapping("/getUserBodyInfoDetial")
    @ResponseBody
    public UserBodyInfo getUserBodyInfoDetial(Integer userid) {
        return userBodyInfoService.selectUserBodyInfoByUserID(userid);
    }
}
